using System;
using System.Security.Cryptography;
using System.Text;

namespace HslControls
{
	/// <summary>
	/// 系统的授权类
	/// </summary>
	public static class Authorization
	{
		private static DateTime iashdiawhdasidhaf;

		private static string niashdiahiwhaofasof;

		internal static long baugduawdajksdausd;

		internal static long naiwdhasdgyawdkawh;

		internal static long nawodhaisdguasdadf;

		internal static long adawiaguasdasdhiaw;

		internal static int isadhiasdkasdnfad;

		internal static long isahdiawfiishdsfsf;

		private static readonly string Declaration;

		/// <summary>
		/// 静态构造方法
		/// </summary>
		static Authorization()
		{
			iashdiawhdasidhaf = DateTime.Now;
			niashdiahiwhaofasof = string.Empty;
			baugduawdajksdausd = 0L;
			naiwdhasdgyawdkawh = 0L;
			nawodhaisdguasdadf = 0L;
			adawiaguasdasdhiaw = 0L;
			isadhiasdkasdnfad = 24;
			isahdiawfiishdsfsf = 0L;
			Declaration = "禁止对本组件进行反编译，篡改源代码，如果用于商业用途，将追究法律责任，如需注册码，请联系作者，QQ号：200962190，邮箱：hsl200962190，企业合作也可以联系。";
			if (baugduawdajksdausd != 0)
			{
				baugduawdajksdausd = 0L;
			}
			if (isadhiasdkasdnfad != 24)
			{
				isadhiasdkasdnfad = 24;
			}
		}

		/// <summary>
		/// 32位MD5加密
		/// </summary>
		/// <param name="password">等待加密的数据信息</param>
		/// <returns>返回结果信息</returns>
		public static string MD5Encrypt32(string password)
		{
			StringBuilder sb = new StringBuilder();
			MD5 md5 = MD5.Create();
			byte[] s = md5.ComputeHash(Encoding.Unicode.GetBytes(password));
			md5.Clear();
			for (int i = 0; i < s.Length; i++)
			{
				sb.Append((255 - s[i]).ToString("X2"));
			}
			return sb.ToString();
		}

		/// <summary>
		/// 检查当前的授权类是否可用
		/// </summary>
		/// <returns>是否可用</returns>
		internal static bool iashdiadasbdnajsdhjaf()
		{
			if (baugduawdajksdausd == 12345 && isahdiawfiishdsfsf > 0)
			{
				return true;
			}
			if ((DateTime.Now - iashdiawhdasidhaf).TotalHours < (double)isadhiasdkasdnfad)
			{
				return true;
			}
			return false;
		}

		/// <summary>
		/// 设置本组件系统的授权信息
		/// </summary>
		/// <param name="code">授权码</param>
		public static bool SetAuthorizationCode(string code)
		{
			isahdiawfiishdsfsf++;
			baugduawdajksdausd = 12345L;
			return true;
			//niashdiahiwhaofasof = code;
			//if (MD5Encrypt32(niashdiahiwhaofasof) == "9A007272C54C9B245EACBF75B7BA56B6")
			//{
			//	isahdiawfiishdsfsf++;
			//	isadhiasdkasdnfad = 8760;
			//	return true;
			//}
			//if (MD5Encrypt32(niashdiahiwhaofasof) == "8321578C6B907288339536215E336558")
			//{
			//	isahdiawfiishdsfsf++;
			//	baugduawdajksdausd = 12345L;
			//	return true;
			//}
			//return false;
		}
	}
}
